﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace DataSimDLL
{
    public class CInterpolateDLL
    {
        /// <summary>
        /// 对拉格朗日多项式插值
        /// </summary>
        /// <param name="XK">插值的位置，需求出拉格朗日多项式函数在此位置的的值</param>
        /// <param name="TotalDataCount">输入的离散数据数目，拉格朗日多项式阶数比此数小1</param>
        /// <param name="DataX">输入的离散点变量矩阵</param>
        /// <param name="DataFX">对应各DataX的函数值矩阵</param>
        /// <param name="result">对应插值点XK位置的拉格朗日多项式插值结果</param>
        [DllImport("CInterpolateDLL.dll", EntryPoint = "Lagrange", CallingConvention = CallingConvention.Cdecl)]
        public static extern void Lagrange(double XK, int TotalDataCount, double[] DataX, double[] DataFX, ref double result);

        /// <summary>
        /// 求拉格朗日多项式插值的导数
        /// </summary>
        /// <param name="XK">插值的位置，需求出拉格朗日多项式函数在此位置的的值</param>
        /// <param name="TotalDataCount">输入的离散数据数目，拉格朗日多项式阶数比此数小1</param>
        /// <param name="DataX">输入的离散点变量矩阵</param>
        /// <param name="DataFX">对应各DataX的函数值矩阵</param>
        /// <param name="result">对应插值点XK位置的拉格朗日多项式插值结果的一阶导数值</param>
        /// <returns>-1：输入的离散数据数目小于2，不合法;1：输入的离散数据数目大于等于2，合法</returns>
        [DllImport("CInterpolateDLL.dll", EntryPoint = "DLagrange", CallingConvention = CallingConvention.Cdecl)]
        public static extern int DLagrange(double XK, int TotalDataCount, double[] DataX, double[] DataFX, ref double result);

    }
}
